﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using PiaoanWeb.AppLogic.DataAccessLayer;
namespace PiaoanWeb.AppLogic.BusinessLogicLayer
{
    [System.ComponentModel.DataObject(true)]
    public class CategoriesBLL : IDisposable
    {
        DatabaseContext _DatabaseContext;
        public CategoriesBLL():this(new DatabaseContext())
        { 
        }

        public CategoriesBLL(DatabaseContext DatabaseContext)
        {
            _DatabaseContext = DatabaseContext;
        }

        public void Dispose()
        {
            if (_DatabaseContext != null)
            {
                _DatabaseContext.Dispose();
                _DatabaseContext = null;
            }

            GC.SuppressFinalize(this);
        }

        public void AddCategory(Categories newCategory)
        {
            _DatabaseContext.Categories.Add(newCategory);
            _DatabaseContext.SaveChanges();
        }

        public List<Categories> GetAllCategoriesExcludeDeleted()
        {
            return _DatabaseContext.Categories.Where(c => c.IsActive).ToList();
        }

        public List<Categories> GetAllCategoriesIncludeDeleted()
        {
            return _DatabaseContext.Categories.ToList();
        }
    }
}